<?php
include_once "com/code/searchengine/SearchEngineController.php";
include_once "com/code/video/searchengine/VideoSearchEngineModel.php";

class VideoSearchEngineController extends SearchEngineController {
	
	private $entityListControllerId;
	
	public function __construct($params) {
		parent::__construct($params);
		
		$this->entityListControllerId = Controller::newId("EntityListController", $params);
	}
	
	public function __destruct() {
		if ($this->deleted()) {
			$entityListController = $this->getEntityListController();
			if (!empty($entityListController)) {
				$entityListController->sessionDelete();
			}
		}
		
		parent::__destruct();
	}
	
	public function getEntityListController() {
		return Controller::getController("EntityListController", $this->entityListControllerId);
	}
	
	public function getSearchEngineView($params) {
		$view = new View("com/code/video/searchengine/VideoSearchEngineView.php");
		$view->assignController($this);
		
		ob_start();
		EntityListController::getEntityListView($params);
		$entityListView = ob_get_contents();
		ob_end_clean();

		$vars = array();
		$vars["entityListView"] = $entityListView;

		$view->display($vars);
	}
	
	public static function search($params) {
		$keywords = $params['keywords'];
		$videoSearchEngineModel = new VideoSeacrhEngineModel();
		$beans = $videoSearchEngineModel->search($keywords);
		echo json_encode($beans);
	}
	
	public function getEntityListId($params) {
		$entityListController = $this->getEntityListController();
		$id = $entityListController->getControllerIdentifier();
		echo "(".json_encode($id).")";
	}
}
?>